<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //  编写 `getAverageAge(users)` 函数，该函数获取一个具有 `age` 属性的对象数组，并返回平均年龄。
        // 平均值的计算公式是 `(age1 + age2 + ... + ageN) / N`。.
        let arr = [{
            name: "John",
            age: 25
        }, {
            name: "Pete",
            age: 30
        }, {
            name: "Mary",
            age: 28
        }];

        function getAverageAge(users) {
            // var sum = 0;
            // users.forEach(element => {
            //     sum += element.age;
            // });
            // return sum / users.length;.
            var sum = 0;
            users.map(e => {
                sum += e.age;
            })
            return sum / users.length;

        }
        console.log(getAverageAge(arr));
    </script>
</body>

</html>